<!DOCTYPE html>
<html>
<head>
    <title>编辑资料</title>
    #parse("include/head.html")
</head>

<body>
<!--头部-->
#parse("include/nav.html")
<!--头部 end-->


<div class="container clear">
    <div class="boboer personal-left">
        <dl>
            <dt><img id="headPreview" src=" #if ($profile.avatar) $profile.avatar
                #else $request.contextPath/res/images/head.jpg
                #end" /></dt>
            <dd>
                <h2 id="nick">$profile.nickname</h2>
                <p>账号：$profile.uid</p>
                <p>上次直播：昨天</p>
                <p>TA的粉丝：$profile.followerCnt</p>
                <p>TA的关注：$profile.followingCnt</p>
            </dd>
<!--            <a id="followBtn" href="javascript:void(0)" onclick="FollowBtnClick($user.uid)"
               class="btn #if ($op.Followed) dissable #else red #end "><i class="follow"></i>
                <span>#if ($op.Followed) 已#end关注</span>
            </a>
            <a id="praiseBtn" href="javascript:void(0)" onclick="addFav($user.uid)"
               class="btn #if ($op.Liked) dissable #else yellow-b #end"><i class="praise"></i>
                <span>#if ($op.Liked) 已#end点赞</span>
            </a>-->
        </dl>
    </div>

    <div class="personal-right">
        <div class="title">编辑资料</div>
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="personal-info-edit">
            <tr>
                <td width="60" align="right">头　像：</td>
                <td><img id="headEdit" onclick="uploadHead()" src="
                #if ($profile.avatar) $profile.avatar
                #else $request.contextPath/res/images/head.jpg
                #end"
                         class="head"></td>
            </tr>
            <tr>
                <td align="right">昵　称：</td>
                <td><input name="nickname" value="$profile.nickname" placeholder="昵称" type="text" style="width:200px"></td>
            </tr>
            <tr class="boboer">
                <td align="right">性　别：</td>
                <td>
                    <select name="gender" id="gender" class="select-t">
                        <option #if($profile.gender == 1) selected #end value="1">男</option>
                        <option #if($profile.gender == 2) selected #end value="2">女</option>
                    </select>
                </td>
            </tr>
            <tr class="boboer">
                <td align="right">所在地：</td>
                <td>
                    <select id="provinceList" class="select-t">
                    </select>

                    <select id="cityList" class="select-t">
                    </select>

                    <select id="regionList" class="select-t">
                    </select>
                </td>
            </tr>
            <tr class="boboer">
                <td align="right">身　高：</td>
                <td><input name="height" id="height" value="$profile.height" type="text" placeholder="身高"></td>
            </tr>
            <tr class="boboer">
                <td align="right">体　重：</td>
                <td><input name="height" id="weight" value="$profile.weight" type="text" placeholder="体重"></td>
            </tr>
            <tr class="boboer">
                <td align="right">三　围：</td>
                <td><input name="bwn" id="bwn" type="text" value="$profile.bwn" placeholder="三围"></td>
            </tr>
            <tr>
                <td align="right">&nbsp;</td>
                <td><a onclick="Done();" href="javascript:void(0);" class="btn red text_c">完&nbsp;&nbsp;成</a></td>
            </tr>
        </table>
    </div>
</div>

<!--底部-->
#parse("include/footer.html")
<!--底部 end-->
<input style="display:none;" name="file" id="albums" type="file" placeholder=""/>
#parse("include/libs.html")
<script type="text/javascript" src="$request.contextPath/res/dic/region.min.js"></script>
<script type="text/javascript" src="$request.contextPath/res/dic/regionHelper.js"></script>
<script type="text/javascript" src="$request.contextPath/res/plugin/jquery.ajaxfileupload.js"></script>
<script>
    $(function(){
        if (!isLogin()) {
            layer.msg("请先登录");
            load(basePath);
        }
        updateNav("#backnav");
        $("input[type='text']").each(function(){
            $(this).change(simpleChange);
        });

        $("input[name='gender']").each(function(){
            $(this).click(simpleChange);
        });

        RegionHelper.InitHometomeArea($profile.hometownId);
        RegionHelper.checkDone = function (provinceId , cityId , regionId) {
            saveProfile("hometownId", regionId);
        }

        $("#constellation").change(simpleChange);
        $("#gender").change(simpleChange);

        if($isBoer == false) {
            $(".boboer").hide()
        }
    });

    function uploadHead() {
        $('#albums').trigger('click');
    }

    function simpleChange() {
        if($(this).attr("name") == 'bwn') {
            var r =/[0-9]+(.[0-9]+)?-[0-9]+(.[0-9]+)?-[0-9]+(.[0-9]+)?/;
            var res = r.exec($(this).val())
            if (res == null || res[0] != $(this).val()) {
                layer.msg("请按照xx-xx-xx的格式输入",{icon:5});
                return;
            }
        } else if($(this).attr("name") == 'height' || $(this).attr("name") == 'weight') {
            var r =/[0-9]+(.[0-9]+)?/;
            var res = r.exec($(this).val())
            if (res == null || res[0] != $(this).val()) {
                layer.msg("请输入有效数字",{icon:5});
                return;
            }
        }
        saveProfile($(this).attr("name"), $(this).val());
        if($(this).attr("name") == 'nickname') {
            $("#nick").html($(this).val());
        }
    }
    var loadingIndex;
    $('input[type="file"]').ajaxfileupload({
        action: basePath+'/commons/upload?thumbnail=1',
        valid_extensions : ['jpeg','jpg','png','gif','JPEG','JPG','PNG','GIF'],
        params: {
            file: 'file'
        },
        onComplete: function(response) {
            layer.msg("上传成功");
            saveProfile('avatar', response.url);
            layer.close(loadingIndex);
            $("#headPreview").attr('src',response.url);
            $("#headEdit").attr('src',response.url);
        },
        onStart: function() {
            console.log("开始上传...");
            loadingIndex = layer.load(1);
            if ($(this)[0].files[0].size > 5*1024*1024) {
                layer.msg("文件大小不能超过5M",{icon:5});
                return false;
            }
        },
        onCancel: function() {
            console.log('no file selected');
        }
    });

    function Done() {
        document.location.href = document.referrer;
    }

</script>
</body>
</html>
